package element.synt;

import ast.AstItem;
import ast.BlockStatement;
import ast.Statement;
import element.base.Synt;

import java.util.List;

public class Block extends Synt {
    @Override
    public AstItem toAst() {
        BlockStatement statement = new BlockStatement();
        int stmtCount = getNodes().size() - 2;

        for (int i = 0; i < stmtCount; i++) {
            BlockItem blockItem = (BlockItem) getNodes().get(i + 1);
            List<AstItem> items = blockItem.toAsts();

            for (AstItem item: items) {
                statement.statements.add((Statement) item);
            }
        }

        return statement;
    }
}
